<template>
  <div class="container">
    <!-- banner广告轮播-elementUI走马灯 -->
    <el-carousel>
      <el-carousel-item v-for="item in images" :key="item.category_id">
        <img
          :src="'http://localhost:3001/' + item.category_pic"
          class="bannerimg"
          @click="handleCategory(item.category_id)"
        />
      </el-carousel-item>
    </el-carousel>
    <!-- 正在热映,即将上映路由 -->
    <div class="nav">
      <router-link to="/home/in_theaters">文章列表</router-link>
      <router-link to="/home/comment">留言板</router-link>
    </div>
    <!--router-view展示正在热映,即将上映路由切换的结果  -->
    <keep-alive>
      <router-view></router-view>
    </keep-alive>
    <div class="button">
      <div @click="handleClickmoive()" class="point">
        <i class="el-icon-orange"></i>
        <p>文章列表</p>
      </div>
      <div @click="handleClickConsult()" class="point">
        <i class="el-icon-chat-line-square"></i>
        <p>留言板</p>
      </div>
      <div @click="handleClickTeam()" class="point">
        <i class="el-icon-user"></i>
        <p>关于团队</p>
      </div>
    </div>
  </div>
</template>

<script>
import axios from 'axios'

export default {
  data() {
    return {
      bannerHeight: 200,
      images: [],
    }
  },
  activated() {
    // 调用接口拿到图片
    axios.get('http://localhost:3001/category').then((res) => {
      // console.log(res.data.result.data)
      this.images = res.data.result.data
    })
  },
  // 设置轮播样式1
  mounted() {
    this.setSize()
    window.addEventListener(
      'resize',
      () => {
        this.setSize()
      },
      false
    )
  },
  methods: {
    setSize() {
      // 设置轮播样式2
      this.bannerHeight = document.body.clientWidth / 4
    },
    handleClickmoive() {
      //跳转正在热映
      this.$router.push('/home/in_theaters')
    },

    handleClickConsult() {
      //跳转留言板
      this.$router.push('/home/comment')
    },
    // 跳转关于
    handleClickTeam() {
      this.$router.push('/team')
    },
    // 跳转相应的分类文章
    handleCategory(id) {
      // 拿到分类ID号
      console.log(id)
      this.$router.push({
        path: `/cadetail/${id}`,
      })
    },
  },
}
</script>

<style scoped>
/* 响应式布局 */
.bannerimg {
  width: 100%;
  /* height: inherit; */
  height: 400px;
}
* {
  padding: 0;
  margin: 0;
}
.container {
  position: relative;
}
.city {
  position: absolute;
  cursor: pointer;
  z-index: 1000;
  left: 10px;
  top: 10px;
}
.city a {
  color: #fff;
}

img {
  width: 100%;
  height: 100%;
}
.nav {
  display: flex;
  justify-content: space-around;
  line-height: 50px;
  margin-bottom: 10px;
}
.nav a {
  color: black;
}
.nav .router-link-active {
  color: orangered;
  border-bottom: 2px solid orangered;
}
a {
  text-decoration: none;
}
/* 底部 */
.button {
  display: flex;
  justify-content: space-between;
}
.button > div {
  height: 70px;
  width: 80px;
  text-align: center;
}
.point:hover {
  cursor: pointer;
  color: orange;
}
</style>
